package org.socialresume.client.mvp.view;

import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.ui.HasValue;
import com.google.gwt.user.client.ui.UIObject;

public class VisibilityWrapper implements HasValue<Boolean>{
	
	private HandlerManager localManager;
	private UIObject object;
	
	public VisibilityWrapper(UIObject object) {
		localManager = new HandlerManager(this);
		this.object = object;
	}
	
	@Override
	public Boolean getValue() {
		return object.isVisible();
	}

	@Override
	public void setValue(Boolean value) {
		setValue(value, false);
	}

	@Override
	public void setValue(Boolean value, boolean fireEvents) {
		object.setVisible(value);
		if(fireEvents){
			ValueChangeEvent.fire(this, value);
		}
	}

	@Override
	public HandlerRegistration addValueChangeHandler(
			ValueChangeHandler<Boolean> handler) {
		return localManager.addHandler(ValueChangeEvent.getType(), handler);
	}

	@Override
	public void fireEvent(GwtEvent<?> event) {
		localManager.fireEvent(event);
	}
	
}
